﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace AzukiMapUI
{
	public partial class MessageBox : UserControl
	{
        string _message;
        MessageTypes _messageType;

        public string Message
        {
            get { return _message; }
            set { 
                _message = value;
                SetMessage();
            }
        }

        public MessageTypes MessageType
        {
            get { return _messageType; }
            set { 
                _messageType = value;
                SetMessage();
            }
        }

		public MessageBox()
		{
			// Required to initialize variables
			InitializeComponent();
            _messageType = MessageTypes.Info;
            _message = "???";
            SetMessage();
            AddBoxOnLayoutRoot();
		}

        public MessageBox(string message, MessageTypes type)
        {
			// Required to initialize variables
			InitializeComponent();
            _messageType = type;
            _message = message;
            SetMessage();
            AddBoxOnLayoutRoot();
        }

        void AddBoxOnLayoutRoot()
        {
            Grid layoutRoot = ((Page)Application.Current.RootVisual).LayoutRoot;
            int gridRows =layoutRoot.RowDefinitions.Count;
            int gridCols = layoutRoot.ColumnDefinitions.Count;
            this.SetValue(Grid.ColumnSpanProperty, gridCols);
            this.SetValue(Grid.RowSpanProperty, gridRows);
            layoutRoot.Children.Add(this);
        }

        void SetMessage()
        {
            TbMessage.Text = _message;

        }

        void SetIcon()
        {
            HideAllIcons();
            switch (MessageType)
            {
                case MessageTypes.Info:
                    IconInfo.Visibility = Visibility.Visible;
                    break;
                case MessageTypes.Warn:
                    IconWarn.Visibility = Visibility.Visible;
                    break;
                case MessageTypes.Error:
                    IconError.Visibility = Visibility.Visible;
                    break;
            }
        }

        void HideAllIcons()
        {
            IconInfo.Visibility = Visibility.Collapsed;
            IconWarn.Visibility = Visibility.Collapsed;
            IconError.Visibility = Visibility.Collapsed;
        }

        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            
        }
	}

    public enum MessageTypes
    {
        Info,
        Warn,
        Error,
    }
}